﻿using System;
using System.Collections.Generic;

namespace Tracker
{
  public static class Angle
  {
    public static double ToDegree(double a)
    {
      return Math.Round(a*kRadian);
    }

    public static double ToRadian(int a)
    {
      return a * kInvRadian;
    }

    public static double ToRadian(double a)
    {
      return a * kInvRadian;
    }

    public static int Normalize(int a)
    {
      int b = a % 360;
      return (b < 0) ? (b + 360) : b;
    }

    public static double Normalize(double a)
    {
      double b = Math.IEEERemainder(a, 360.0);

      if (b < 0.0)
      {
        b += 360.0;
      }

      return b;
    }

    public static int Sweep(int s, int e)
    { 
      return e >= s ? (e - s) : (e + 360 - s); 
    }

    public static double Sweep(double s, double e)
    { 
      return e >= s ? (e - s) : (e + 360 - s);
    }

    public static double Degree(double x, double y)
    {
      return Normalize(kRadian * Math.Atan2(y, x));
    }

    public static int DegreeInt(double x, double y)
    {
      return Normalize((int)Math.Round(kRadian * Math.Atan2(y, x)));
    }

    public static double Radian(double x, double y)
    {
      return Math.Atan2(y, x);
    }

    public static bool Contain(int a, int s, int e)
    {
      if (e > s)
      {
        return a >= s && a <= e;
      }
      else if (s > e)
      {
        return a >= s || a <= e;
      }
      else
      {
        return a == s;
      }
    }

    public static double Sin(int a)
    {
      return Math.Sin(ToRadian(a));
    }

    public static double Sin(double a)
    {
      return Math.Sin(ToRadian(a));
    }

    public static double Cos(int a)
    {
      return Math.Cos(ToRadian(a));
    }

    public static double Cos(double a)
    {
      return Math.Cos(ToRadian(a));
    }

    public const double	kPi        = 3.1415926535898;
    public const double	kRadian    = 180.0 / kPi;
    public const double kInvRadian = kPi / 180.0;
  }
}
